<template>
  <div class="overview">
    <div class="row one">
      <div class="profit_title">收益率</div>
      <div class="total_profitrate">{{totalProfitRate}}%</div>
      <div class="total_profit" :class="totalProfit <0 && totalProfit!='--' ?'loss_bg':''">{{totalProfit}}</div>
      <div class="changecount">平均每月调仓<span class="month_changecount">{{monthChangeCount}}</span>次</div>
      <div class="group_name"><span>组合</span><span id="groupName">{{groupName}}</span></div>
    </div>
    <div class="row two">
      <div class="text-center userhead" v-if="userCode!=clientId"><img class="user_head" :src="userHead"></div>
      <div class="text-left usercreate" :class="userCode == clientId?'selfcreate':''">
        <span class="nick_name" id="nickName">{{userCode == clientId? '&nbsp;':nickname}}</span>
        <div class="create">
          <div>{{userCode == clientId? '我&nbsp;':''}}创建于</div>
          <div class="create_date">{{createDate}}</div>
        </div>
      </div>
      <div class="text-right dingyue">
        <div><i class="iconfont icon-dingyue"></i></div>
        <div class="bstealnum">{{bstealNum}}</div>
        <div>人偷师</div>
      </div>
    </div>
    <div class="wave">
      <img src="~assets/images/portfolio/waveorange@2x.png" width="100%" height="40px">
    </div>
    <div class="introlink"><i class="iconfont icon-wenhao" @click="toGroupIntroduce"></i><span
      @click="toGroupIntroduce">什么是组合?</span></div>
  </div>
</template>

<script>
  import Constant from 'common/constant'
  import RemoteDAO from 'common/remoteDAO'
  import LocalDAO from 'common/localDAO'
  import CommonUtil from 'common/common.util'
  import _ from 'underscore'

  export default {
    name: 'OverView',
      data () {
      return {
        userHead:'',
        nickname:'--',
        error:'error'
      }
    },
    props: {
      userCode:{type: String},
      clientId:{type: String},
      groupName: {type: String},
      totalProfitRate: {type: String},
      totalProfit: {type: String},
      monthChangeCount: {type: String},
      createDate: {type: String},
      bstealNum: {type: String}
    },
    created: function (){
      this.userHead = CommonUtil.getDefaultUserHead(this.clientId) || Constant.url.DEFAULT_USER_HEAD;
      this.fetchData();
    },
    watch: {
      '$route.query.groupId' (to, from) {
        //跳转相同页面，组件不重新构建，无法调用created,故需监听
        this.fetchData ()
      }
    },
    methods: {
      toGroupIntroduce(){
        this.$router.push({path:'/groupIntroduce'})
      },
      fetchData(){
        var self = this;
        //用户资料
        RemoteDAO.callUC12008316(self.userCode,self.clientId,function(response){
          var userData = {"USER_HEAD":"",'NICKNAME':""};
          if(Number(response.error) === 0) {
            userData = response.data.body[0];
          }
          self.userHead = userData.USER_HEAD || self.userHead; //头像
          self.nickname = userData.NICKNAME || self.nickname;  //昵称
          self.$store.dispatch('setGroupNickname',self.nickname)
          if(Number(response.error) === 1){
            self.error = response.data;
          }else if(userData.NICKNAME == ''){
            self.error="用户信息获取失败";
          }

          //更新分享数据
          var shareGroup = LocalDAO.getShareGroup();
          _.extend(shareGroup.group_data,{"user_head": self.userHead, "nick_name": self.nickname});
          LocalDAO.setShareGroup(shareGroup);
        });
      }
    }
  }
</script>

<style scoped>

</style>
